<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="明月">
    <title>百度新闻</title>
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            padding: 0;
            width: 100%;
        }

        section {
            width: 100%;
            height: 30px;
            border: 1px solid #eee;
        }

        .top {
            width: 900px;
            height: 30px;
            margin-left: 1050px;
        }

        section a {
            color: black;
            margin: 0 10px;
            font-size: 15px;
        }

        .center {
            text-align: center;
        }

        .center img {
            width: 135px;
            height: 45px;
            vertical-align: middle;
            margin-right: 20px;
            position: relative;
            bottom: 10px;
        }

        .baidu {
            width: 100px;
            height: 40px;
            background-color: #3388ff;
            border: none;
            text-align: center;
            color: white;
            margin: 30px 10px 0 -5px;
        }

        .center a {
            color: black;
            font-size: 14px;
        }

        nav {
            width: 100vw;
            height: 40px;
            background-color: #01204F;
        }

        ul {
            width: 1200px;
            height: 40px;
            line-height: 20px;
            text-align: center;
            list-style: none;
            margin: 0 auto;
            display: flex;
            justify-content: space-around;
        }

        ul li {
            padding: 10px 15px;
            color: #eee;
            cursor: pointer;
        }

        main {
            width: 100vw;
            height: 1000px;
        }

        .active{
            background-color: #CC0000;
        }

        button {
            width: 50px;
            height: 50px;
            font-size: 30px;
            background-color: skyblue;
            position: relative;
            left: 1600px;
            bottom: 200px;
            position: fixed;
            display: none;
        }
    </style>
</head>

<body>
    <section>
        <div class="top">
            <a href="">网页</a>
            <a href="">新闻</a>
            <a href="">贴吧</a>
            <a href="">知道</a>
            <a href="">音乐</a>
            <a href="">图片</a>
            <a href="">视频</a>
            <a href="">地图</a>
            <a href="">文库</a>
            <a href="">|</a>
            <a href="">百度首页</a>
            <a href="">登录</a>
            <a href="">注册</a>
            <a href="">百度新闻客户端</a>
        </div>
    </section>
    <div class="center">
        <img src="logo.png" alt="">
        <input type="text" name="" value="" style="width:400px;height:40px;">
        <input type="text" value="百度一下" class="baidu">
        <a href="">帮助</a>
        <a href="">高级搜索</a>
        <a href="">设置</a><br>
        <input type="radio" name="news" value="" style="margin:0 0 10px -300px;">新闻全文
        <input type="radio" name="news" value="">新闻标题
    </div>
    <nav>
        <ul>
            <li class="active">首页</li>
            <li>百家号</li>
            <li>国内</li>
            <li>国际</li>
            <li>军事</li>
            <li>社会</li>
            <li>财经</li>
            <li>娱乐</li>
            <li>体育</li>
            <li>互联网</li>
            <li>科技</li>
            <li>游戏</li>
            <li>时尚</li>
            <li>女人</li>
            <li>汽车</li>
            <li>个性推荐</li>
            <li>更多^</li>
        </ul>
    </nav>
    <main></main>
    <button type="text" onclick="ding()">&#8593;</button>
</body>

</html>
<script>
    // alert(document.body.scrollTop);
    var button = document.querySelector('button');
    var nav = document.querySelector('nav');
    window.onscroll = function () {
        var scrollTop = document.scrollingElement.scrollTop;
        if (scrollTop > 114) {
            // console.log('固定位置');
            nav.style.position = 'fixed';
            nav.style.top = '0';
            button.style.display = 'block';
        } else {
            nav.style.cssText = '';
            button.style.display = 'none';
        }
    }
//置顶
    function ding() {
       document.scrollingElement.scrollTop=0;
    }

    var lis = document.querySelectorAll('li');
    for (var i = 0; i < lis.length; i++) {
        lis[i].index = i;
        lis[i].onmouseover = function () {
            for (var i = 0; i < lis.length; i++) {
                lis[i].className = ''; 
            }
            this.className = 'active';
             lis[0].className='active';
        }
         lis[i].onmouseout = function (){
              this.className = '';
         }
    }
</script>